package com.sams.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

public class ExceptionResolver implements HandlerExceptionResolver {

	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
			Exception ex) {
		 //创建ModelAndView
        ModelAndView mv=new ModelAndView();
        
		Exception customException=null;
		  if(ex instanceof MaxUploadSizeExceededException){
	            customException= (Exception ) ex;
	            mv.addObject("error","上传的文件总长度超过限制，每个文件最大不能超过100kb");
	        }else {
	            customException=new CustomException("系统正在维护。。。"+ex.getMessage());
	           
		        mv.addObject("error",ex.getMessage());
		     
	        }
		   mv.setViewName("error");
	        return mv;
	}
	

}
